package com.erp.view;

import androidx.appcompat.app.AlertDialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.erp.R;

/**
 * Created by Administrator on 2017/2/13/013.
 * 作者：刘洋
 */
public class MyAlerDialog {
    private Context mcontext;
    private AlertDialog mydialog;
    private TextView tvTitle,tvData,tvLeft,tvRight;
    private View view;
    public MyAlerDialog(Context context){
        this.mcontext=context;
    }
    public AlertDialog getdialog(){
        return mydialog;
    }
    public void start(){
        mydialog=new AlertDialog.Builder(mcontext).create();
        mydialog.show();
        mydialog.getWindow().setContentView(R.layout.dialog_mydialog);
        tvTitle= (TextView) mydialog.findViewById(R.id.tv_title);
        tvData= (TextView) mydialog.findViewById(R.id.tv_data);
        tvLeft= (TextView) mydialog.findViewById(R.id.tv_left);
        tvRight= (TextView) mydialog.findViewById(R.id.tv_right);
        view=mydialog.findViewById(R.id.view);
    }
    public void setTitle(String title){
        tvTitle.setText(title);
        tvTitle.setVisibility(View.VISIBLE);
    }
    public void setdata(String data){
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
    public void setleft(String left, View.OnClickListener onClickListener){
        tvLeft.setText(left);
        if(onClickListener!=null) {
            tvLeft.setOnClickListener(onClickListener);
        }
        tvLeft.setVisibility(View.VISIBLE);
    }
    public void setright(String right, View.OnClickListener onClickListener){
        tvRight.setText(right);
        if(onClickListener!=null) {
            tvRight.setOnClickListener(onClickListener);
        }
        tvRight.setVisibility(View.VISIBLE);
    }
    public void show(){
        if(tvRight.getText().toString()!=""&&tvLeft.getText().toString()!=""){
            view.setVisibility(View.VISIBLE);
        }else{
            view.setVisibility(View.GONE);
        }
    }
    public void dismiss(){
        if(mydialog!=null){
            mydialog.dismiss();
        }
    }
}
